<template>
	<view class="header">
		<image :src="getDateil.images?getDateil.images:'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'" style="width: 150rpx; height:150rpx;"></image>
		<view>
			<text class="Uname">{{getDateil.Uname?getDateil.Uname:"匿名用户"}}</text><br />
			<text class="detail">君Q：{{getDateil.code?getDateil.code:"xxxxxx"}}</text>
		</view>
		<view style="text-align: center;margin-left: 50rpx;">
			<u-icon :name = "1?'man':'woman'" size="28"></u-icon>
		</view>
		<view class="cancel">
			<u-button v-if="islogin == false" text="请您登录聊天" type="primary" @click="religon"></u-button>
			<u-button v-else text="退出登录" type="error" @click="modelShow = true"></u-button>
		</view>
		<u-modal :show="modelShow" :title="modelTitle"
		 :content='modelContent'
		showCancelButton
		showConfirmButton
		@confirm = "enter"
		@cancel = "modelShow = false"
		 ></u-modal>
	</view>
	
</template>

<script>
	import api from "@/until/api.js"
	export default {
		data(){
			return{
				//1 男 2 女
				name:1,
				modelShow:false,
				modelContent:"退出后所有数据将抹除，跟洛洛的数据也会被抹除哦",
				modelTitle:"是否退出",
				getDateil:{
					images:"",
					Uname:"",
					code:""
				},
				islogin:false,
				name_index: 0
			}
		},
		
		onLoad() {
			uni.$once("update",(e)=>{
				this.getdetail()
			})
			this.getdetail()
		},
		methods:{
			getdetail(){
				api.geturltest().then(res=>{
					if(res.data.code == 200){
						console.log(1)
						this.islogin = true
						let { Date,TextURl,imgurl } = res.data.data
						this.getDateil.images = imgurl
						this.getDateil.Uname = TextURl
						this.getDateil.code = Date
					}else if(res.data.code == 301){
						console.log(2)
						this.getDateil.images = null
						this.getDateil.Uname = null
						this.getDateil.code = null
					}
				})
			},
			enter(){
				api.exit().then(res=>{
					uni.showToast({
						title:"退出成功",
						icon:"success",
						duration:2000,
					})
					uni.removeStorageSync("token")
					this.getdetail()
					this.modelShow = false
					this.islogin = false
				})
			},
			religon(){
				uni.navigateTo({url:'/pages/login/index'})
			}
		}
	}
	
</script>

<style lang="scss" scoped>
	.header{
		width: 95%;
		margin: 0rpx auto;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 30rpx 0;
		image{
			width: 60rpx;
			height: 60rpx;
			border-radius: 10rpx;
			margin: 20rpx;
		}
		view{
			margin-top: 10rpx;
		}
		
	}
	.cancel{
		margin-left: 20rpx	;
	}
	.Uname{
		font-size: 1.5rem;
		font-weight: 600;
		
	}
	.detail{
		color:#ccc
	}
	
</style>